<template>
	<view class="yz" @click="onRead" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend">
		<view class="list-item flex ali-cen padd30">
			<view class="list-item-left mr30">
				<image class="yicon-lg radius50p" :src="item.UserInfo[0].avatar"></image>
			</view>
			<view class="list-item-right" :class="{'fo-gray':item.IsRead}">
				<text class="flex1 over-two-line">
					<text class="mr10">{{item.UserInfo[0].Nickname}}</text>
					<text class="mr10">{{NoticeType}}</text>
					<text v-if="item.noticeType===1">您</text>
					<template v-if="item.noticeType===2">
						<text v-if="item.CommonInfo.length>0">{{item.CommonInfo[0].commonValue}}</text>
						<text v-else class="txt-lineThrough">该文章或评论已被删除</text>
					</template>
				</text>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		API$ReadedNotice
	} from '@/common/API/notice.js'

	let timeStamp = 0; // 时间戳
	let isXYmove = false; //是否在处于上下或者左右滑动中

	export default {
		props: {
			"item": {
				type: Object,
				default: function() {
					return {}
				}
			}
		},
		name: "",
		computed: {
			NoticeType() {
				let TXT = ''
				switch (this.item.noticeType) {
					case 1:
						TXT = '点赞'
						break;
					case 2:
						TXT = '评论'
						break;
					case 3:
						TXT = '关注'
						break;
					case 4:
						TXT = '关注'
						break;
					case 5:
						TXT = '发不新文章'
						break;
					case 6:
						TXT = '收藏'
						break;
					case 7:
						TXT = '分享'
						break;
				}
				return TXT
			}
		},
		data() {
			return {

			}
		},
		methods: {
			// 点击已读
			onRead() {
				// 点击阅读过就不再触发接口了
				if (!this.item.IsRead) {
					uni.$emit('change', {
						type: 'change_IsRead',
						data: this.item
					})
					this.completeRead({
						_id: this.item._id
					})
				}
			},
			touchstart(e) {
				isXYmove = false
				timeStamp = e.timeStamp
			},
			touchmove() {
				if (isXYmove) return // 节约点性能
				isXYmove = true
			},
			touchend(e) {
				if (isXYmove) return isXYmove = false
				let isLongPress = Math.floor((e.timeStamp - timeStamp) / 1000) //长按的时间
				if (isLongPress >= 1) {
					console.log('长按成功')
					uni.$emit('change', {
						type: 'change_YModal', // 分支
						Booleans: true, // 改变拟态框的显示状态
						data: this.item // 数据
					})
				}
			},
			/****************************************************数据接口部分**************************************************************/
			// 完成阅读
			async completeRead(json) {
				let {
					code,
					msg,
					data
				} = await API$ReadedNotice(json)
				console.log(code, msg, data)
			}
		}
	}
</script>

<style scoped lang="less">
	.list-item:active {
		background: rgba(0, 0, 0, 0.1);
		transition: .2s;
	}
</style>
